package com.ybkj.o2o.zhuanche.service.impl;

import com.ybkj.o2o.zhuanche.mapper.BaseMapper;
import com.ybkj.o2o.zhuanche.service.BaseService;

import org.apache.ibatis.session.RowBounds;

import java.util.List;

/**
 * Created by shine on 15/8/19.
 */
public abstract class AbstractBaseService<T, Q, K> implements BaseService<T, Q, K> {

  public abstract BaseMapper<T, Q, K> getMapper();

  @Override
  public T fetch(K primaryKey) {

    return getMapper().selectByPrimaryKey(primaryKey);
  }

  @Override
  public int delete(K primaryKey) {

    return getMapper().deleteByPrimaryKey(primaryKey);
  }

  @Override
  public List<T> findAll() {

    return getMapper().selectByExample(null);
  }

  @Override
  public List<T> findAll(RowBounds rowBounds) {

    return getMapper().selectByExampleWithRowbounds(null, rowBounds);
  }

  @Override
  public long count() {

    return getMapper().countByExample(null);
  }

  @Override
  public int update(T templet) {

    return getMapper().updateByPrimaryKey(templet);
  }

  @Override
  public int updateIngoreNull(T templet) {

    return getMapper().updateByPrimaryKeySelective(templet);
  }

  @Override
  public int insert(T templet) {

    return getMapper().insert(templet);
  }

}
